import {addProjection, addCoordinateTransforms, Projection} from 'ol/proj'
import {applyTransform} from 'ol/extent'
import proj4 from 'proj4/dist/proj4'
import {register} from 'ol/proj/proj4';
import {lngLatToMercator, mercatorToLngLat} from "@/components/ol-map/projection/coordinateTransforms/bd09";
import dbzb from "@/components/ol-map-warp/libs/coordinate-system/dbzb";

// let extent = [72.004, 0.8293, 137.8347, 55.8271];

/**
 * BD:09
 * @returns {Projection}
 */
export function getBD09ProjByCode() {
  proj4.defs("baidu", "+proj=merc +lon_0=0 +units=m +ellps=clrk66 +no_defs");
  register(proj4);
  //定义一个坐标系
  var projBD09 = new Projection({
    code: 'baidu',
    // extent: applyTransform(extent, dbzb.projzh.ll2bmerc),
    units: 'm',
    axisOrientation: 'neu',
    global: true
  })

  addProjection(projBD09)
  addCoordinateTransforms('EPSG:4326', projBD09, lngLatToMercator, mercatorToLngLat)

  // addCoordinateTransforms(
  //   'EPSG:4326',
  //   projBD09,
  //   function (coordinate) {
  //     return dbzb.projzh.ll2bmerc(coordinate)
  //   },
  //   function (coordinate) {
  //     return dbzb.projzh.bmerc2ll(coordinate)
  //   }
  // )


  // addCoordinateTransforms(
  //   'BD:09',
  //   'EPSG:3857',
  //   function (coordinate) {
  //     console.log(888)
  //     return lngLatToMercator(coordinate)
  //   },
  //   function (coordinate) {
  //     return mercatorToLngLat(coordinate)
  //   }
  // )
}
